package cn.wolfcode.luowowo.job;

import cn.wolfcode.luowowo.cache.service.IStrategyStatisVOService;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import cn.wolfcode.luowowo.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

//redis数据持久化
//@Component
public class RedisDataPersistenceJob {

    @Autowired
    private IStrategyStatisVOService strategyStatisVOService;
    
    @Autowired
    private IStrategyService strategyService;
    

    //Seconds Minutes Hours DayofMonth Month DayofWeek Year
    //   0      0       2       1         *     ?       *   表示在每月的1日的凌晨2点调整任务
    //Seconds Minutes Hours DayofMonth Month DayofWeek
    //  0       15      10      ?       *       MON-FRI   表示周一到周五每天上午10:15执行作业
    //启动定时任务，每5秒执行一次任务
    @Scheduled(cron="0/10 * * * * ?")
    public void redisDataPersistenceJob(){
        //查询出redis中的所有strategystaticvo对象
        //更新Strategy中的vo对象中包含的数据
        System.out.println("--------vo对象持久化开始----------");
        List<StrategyStatisVO> list=strategyStatisVOService.queryStrategyStaticVO("*");
        for (StrategyStatisVO vo: list) {
            strategyService.updateStrategyStaticVO(vo);
        }
        System.out.println("--------vo对象持久化结束----------");
    }
}
